import { cleanEnv, str, port } from 'envalid';

const env = cleanEnv(process.env, {
  NODE_ENV: str({ choices: ['development', 'test', 'production'] }),
  PORT: port({ default: 3000 }),
  DATABASE_URL: str(),
  JWT_SECRET: str(),
  JWT_EXPIRATION: str({ default: '24h' }),
  REDIS_URL: str({ default: 'redis://localhost:6379' }),
});

export const config = {
  env: env.NODE_ENV,
  port: env.PORT,
  database: {
    url: env.DATABASE_URL,
  },
  jwt: {
    secret: env.JWT_SECRET,
    expiresIn: env.JWT_EXPIRATION,
  },
  redis: {
    url: env.REDIS_URL,
  },
} as const;

export type Config = typeof config;

export default config;
